home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFlist. Part 2 of 2.
- *
- * Version 2.0, 9-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 29-Jan-91, H Leckner Original version (for CDF V2.0).
- * V1.1 5-Feb-91, J Love Modified error handling.
- * V1.2 12-Feb-91, H Leckner Fixed variable name handling.
- * V1.3 13-Mar-91, H Leckner Fixed attribute entry problem.
- * V1.4 20-Mar-91, H Leckner Fixed problem with large dimension sizes.
- * V1.5 26-Mar-91, J Love Cast malloc calls to proper type. Fix for
- * possible char array overwrite.
- * V1.6 4-Apr-91, H Leckner Fixed problem with filtering REAL8 values.
- * V1.7 5-Jun-91, S Sudarsan Enhanced file/directory input handling
- * along with file_names.c. Changed logical
- * name for HELP directory.
- * V1.8 25-Jun-91, J Love Added QOP. Added CDF_EPOCH as a data type.
- * H Leckner Added #include <sys/types.h>.
- * V1.9 12-Jul-91, J Love TRUE/FALSE. Changed for Cray/UNICOS port.
- * H Leckner Added use of VALIDMIN/VALIDMAX for initial
- * filters (if NSSDC_STANDARD). Use 'Exit' &
- * 'ExitBAD'.
- * V1.10 20-Sep-91, H Leckner Fixed window labeling. Modified for IBM-PC
- * J Love port.
- * V1.11 11-Oct-91, H Leckner Added ability to select more than 8
- * variables.
- * V2.0 9-Mar-91, H Leckner Changed for IBM-RS6000 port. IBM PC port.
- * CDF V2.2.
- *
- ******************************************************************************/
-
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
-
- #if defined(unix)
- #include <sys/types.h>
- #include <sys/stat.h>
- #else
- #if defined (vms)
- #include <descrip.h>
- #else
- #if defined(__MSDOS__)
- #include <dos.h>
- #endif
- #endif
- #endif
-
- #include "cdfdist.h"
- #include "wfl.h"
- #include "kb_def.h"
- #include "utility.h"
- #include "cdflist.h"
-
- void get_field(row_data, col, max_len, value, first_blank, value_entered)
- char row_data[];
- int col;
- int max_len;
- char value[];
- long int *first_blank;
- long int *value_entered;
- {
- long int i;
- *first_blank = NOTTHERE;
- *value_entered = FALSE;
-
- if(strlen(row_data) == 0)
- {
- value[0] = '\0';
- return;
- }
- for (i=col; i<col+max_len; i++)
- {
- value[i-col] = row_data[i-1];
- if(row_data[i-1] != ' ')
- *value_entered = TRUE;
- else
- {
- if(*first_blank == NOTTHERE)*first_blank = i-col;
- }
- }
-
- /*
- if there was a value entered and it is the maximum length tell the program
- that the first blank is the maximum length;
- */
- if(value_entered && *first_blank == NOTTHERE)*first_blank = max_len;
- value[max_len] = '\0';
- }
- void next_field(col_field, select_num, start_page, row, scroll, num_poss)
- long int *col_field;
- long int *select_num;
- long int *start_page;
- int *row;
- long int *scroll;
- long int num_poss;
- {
- if(*col_field > 3)
- {
- *col_field = 1;
- (*select_num)++;
- if(*select_num > num_poss)*select_num = 1;
- (*row)++;
- if(*row > 9)
- {
- *row = 9;
- if(num_poss > 8)
- {
- (*start_page)++;
- if(*start_page > num_poss)*start_page = 1;
- *scroll = TRUE;
- }
- }
- }
- else if(*col_field < 1)
- {
- *col_field = 3;
- (*select_num)--;
- if(*select_num < 1)*select_num = num_poss;
- (*row)--;
- if(*row < 2)
- {
- *row = 2;
- if(num_poss > 8)
- {
- (*start_page)--;
- if(*start_page < 1)*start_page = num_poss;
- *scroll = TRUE;
- }
- }
- }
- }
- long int check_var(display, var, num_poss)
- struct vid_struct display[];
- char var[];
- long int num_poss;
- {
- char mnemonic[CDFLIST_MAX_VAR_LENGTH];
- long int first_blank;
- long int check_len; /* V1.2 */
- long int value_entered;
- long int i;
- long int elem;
- for(i=1; i <= num_poss; i++)
- {
- elem = i * 3;
- /*
- Copy Mnemonic
- */
- get_field(display[elem].label, 6, CDFLIST_MAX_VAR_LENGTH, mnemonic,
- &first_blank, &value_entered);
- check_len = strlen(var); /* V1.2 */
- if(first_blank > check_len)check_len = first_blank;
- if(strncmp(var, mnemonic, check_len) == 0 && value_entered)
- return(DUPLICATE);
- }
- return(OK_RESP);
- }
- void CDFLIST_special_keydef(screen)
- struct GLOBAL_struct *screen;
- {
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- /*
- Load up keypad definitions for selecting a menu item
- */
- key_line1[0] = '\0';
- key_line2[0] = '\0';
- strcat(key_line1,CNTRLM); strcat(key_line1, UP);strcat(key_line1, RET);
- strcat(key_line1,Qdes);
- strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);strcat(key_line2, HLP);
- CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
- }
- void CDFLIST_menu_keydef(screen)
- struct GLOBAL_struct *screen;
- {
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- /*
- Load up keypad definitions for selecting a menu item
- */
- key_line1[0] = '\0';
- key_line2[0] = '\0';
- strcat(key_line1,CNTRLM); strcat(key_line1, UP);
- strcat(key_line1,PUP);strcat(key_line1,HLP);strcat(key_line1,Qdes);
- strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);
- strcat(key_line2,PDOWN);strcat(key_line2,RET);
- CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
- }
- void CDFLIST_load_discrete(values, num_values, col_field, DIS_display,
- num_rows, paste_col)
- char values[];
- long int num_values;
- long int col_field;
- struct vid_struct *DIS_display;
- long int *num_rows;
- long int *paste_col;
- {
- long int i;
-
- for (i=0; i<num_values; i++)
- {
- DIS_display[i].row = 1;
- DIS_display[i].col = 1;
- strcpy(DIS_display[i].label,&values[i*MINMAX_SIZE]);
- DIS_display[i].field_col = 1;
- }
- if((num_values+ROW_OFFSET) > DIS_ROWS)
- *num_rows = DIS_ROWS;
- else
- *num_rows = num_values + ROW_OFFSET;
-
- if(col_field == 3)
- *paste_col = DISMIN_COL_PASTE;
- else
- *paste_col = DISMAX_COL_PASTE;
- }
- CDFstatus CDFLIST_read_VAR(display, possible, num_poss, select, num_select)
- struct vid_struct display[];
- struct variable_struct possible[];
- long int num_poss;
- struct variable_struct select[];
- long int *num_select;
- {
- CDFstatus rcode;
- long int i, j, ii;
- long int found;
- long int len;
- long int field_num;
- double min_max;
- char value[41];
- long int first_blank, check_len; /* V1.2 */
- long int mnemonic_entered;
- long int min_filter_entered;
- long int max_filter_entered;
- Boolean echeck;
- rcode = 0;
- *num_select = 0;
- field_num = 0;
- for (j=1; j<=num_poss; j++)
- {
- field_num = field_num + 3;
- /*
- EXTRACT the VARIABLE name
- */
- get_field(display[field_num].label+display[field_num].field_col-1, 1,
- CDFLIST_MAX_VAR_LENGTH, value, &first_blank, &mnemonic_entered);
- if(mnemonic_entered)
- {
- /*
- VARIABLE NAME WAS ENTERED
- */
- /*
- LOOK in the array of possible variables for the column number
- */
- found = FALSE;
- for(i=0; i<num_poss && !found; i++)
- {
- check_len = strlen(possible[i].var_mnemonic); /* V1.2 */
- if(first_blank > check_len ||
- first_blank == CDFLIST_MAX_VAR_LENGTH)check_len = first_blank;
- if(strncmp(possible[i].var_mnemonic, value, check_len) == 0)
- {
- strcpy(select[*num_select].var_mnemonic,
- possible[i].var_mnemonic);
- select[*num_select].var_num = possible[i].var_num;
- select[*num_select].record_variance =
- possible[i].record_variance;
- for (ii=0; ii< 10; ii++)
- select[*num_select].dim_variances[ii] =
- possible[i].dim_variances[ii];
- select[*num_select].num_bytes = possible[i].num_bytes;
- select[*num_select].num_values= possible[i].num_values;
- select[*num_select].dim_num = possible[i].dim_num;
- /*
- strcpy(select[*num_select].header_name,
- possible[i].header_name);
- */
- select[*num_select].var_mnemonic_len=possible[i].var_mnemonic_len;
- select[*num_select].bin_value = possible[i].bin_value;
- select[*num_select].data_type = possible[i].data_type;
- select[*num_select].scalar = possible[i].scalar;
- found = TRUE;
- }
- }
-
- /*
- RETRIEVE MINIMUM VALUES
- */
- if(select[*num_select].data_type != CDF_EPOCH)
- len = MINMAX_SIZE;
- else
- len = EPOCH_WIDTH;
- get_field(display[field_num+1].label,
- display[field_num+1].field_col-display[field_num+1].col+1,
- len,value,&first_blank, &min_filter_entered);
- if(min_filter_entered)
- {
- if(select[*num_select].data_type != CDF_EPOCH)
- sscanf(value,"%lf",&min_max);
- else
- echeck = check_epoch(value, &min_max);
- select[*num_select].min = min_max;
- }
- /*
- NOW RETRIEVE MAXIMUM VALUE
- */
- get_field(display[field_num+2].label,
- display[field_num+2].field_col-display[field_num+2].col+1,
- len,value,&first_blank, &max_filter_entered);
- if(max_filter_entered)
- {
- if(select[*num_select].data_type != CDF_EPOCH)
- {
- sscanf(value,"%lf",&min_max);
- echeck = TRUE;
- }
- else
- echeck = check_epoch(value, &min_max);
- if(echeck)select[*num_select].max = min_max;
- }
- /*
- Check to see if a filter was entered for this variable or
- if only 1 value was entered
- */
- if(min_filter_entered && !max_filter_entered)
- {
- select[*num_select].max = select[*num_select].min;
- select[*num_select].filter = TRUE;
- }
- else if(!min_filter_entered && max_filter_entered)
- {
- select[*num_select].min = select[*num_select].max;
- select[*num_select].filter = TRUE;
- }
- else if(!min_filter_entered && !max_filter_entered)
- {
- select[*num_select].min = select[*num_select].max;
- select[*num_select].filter = FALSE;
- }
- else
- select[*num_select].filter = TRUE;
- /*
- If there was a filter entered see if the USER entered a
- Minimum value > Maximum value
- */
-
- if((select[*num_select].filter) &&
- (select[*num_select].min > select[*num_select].max))
- {
- *num_select = 0;
- rcode = 1;
- return(rcode);
- }
- else
- *num_select = *num_select + 1;
- }
- }
- return(rcode);
- }
- void CDFLIST_filter(select, num_select, data_values, check_scalar, valid)
- struct variable_struct select[];
- long int num_select;
- union mixed data_values[];
- long int check_scalar;
- long int *valid;
- {
- long int i;
- double value;
-
- *valid = TRUE;
- for (i = 0; i < num_select; i++)
- {
- if(select[i].scalar == check_scalar)
- {
- switch(select[i].data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- value = (double) data_values[i].r4;
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- value = data_values[i].r8;
- break;
- case CDF_INT4:
- value = (double) data_values[i].i4;
- break;
- case CDF_UINT4:
- value = (double) data_values[i].ui4;
- break;
- case CDF_INT2:
- value = (double) data_values[i].i2;
- break;
- case CDF_UINT2:
- value = (double) data_values[i].ui2;
- break;
- case CDF_BYTE:
- case CDF_INT1:
- value = (double) data_values[i].byte;
- break;
- case CDF_UINT1:
- value = (double) data_values[i].ubyte;
- }
- if((select[i].filter) &&
- (value < select[i].filter_min ||
- value > select[i].filter_max))*valid = FALSE;
- }
- }
- }
-
- CDFstatus CDFLIST_put_CDF(new_CDF, record_num, indices, select,
- num_select, data_values)
- struct CDF_struct *new_CDF;
- long int record_num;
- long int indices[10];
- struct variable_struct select[];
- long int num_select;
- union mixed data_values[];
- {
- long int i;
- CDFstatus rcode;
- /*
- PUT VARIABLES INTO CDF
- */
-
- for (i = 0; i < num_select; i++)
- {
- if(select[i].rcode >= CDF_OK) /* V1.1 */
- {
- switch (select[i].data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
- indices, &data_values[i].r4);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
- indices, &data_values[i].r8);
- break;
- case CDF_INT4:
- case CDF_UINT4:
- rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
- indices, &data_values[i].i4);
- break;
- case CDF_INT2:
- case CDF_UINT2:
- rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
- indices, &data_values[i].i2);
- break;
- case CDF_BYTE:
- case CDF_INT1:
- case CDF_UINT1:
- rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
- indices, &data_values[i].byte);
- break;
- case CDF_CHAR:
- case CDF_UCHAR:
- rcode = CDFvarPut(NC.CDF_id, select[i].out_var_num, record_num,
- indices, data_values[i].string);
- }
- }
- }/*var loop*/
- return(rcode);
- }
- CDFstatus CDFLIST_get_discrete(CDF_id, dim_num, var_id, data_type,
- num_values, bin_values, char_values)
- long int CDF_id;
- long int dim_num;
- long int var_id;
- long int data_type;
- long int num_values;
- double bin_values[];
- char *char_values;
- {
- long int indices[10];
- char temp_val[50];
- long int i;
- long int record_num;
- CDFstatus rcode;
- union mixed temp;
-
- record_num = 0;
- for (i=0; i < 10; i++)
- indices[i] = 0;
- for (i=0; i < num_values; i++)
- {
- indices[dim_num-1]=i;
- switch(data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.r4);
- bin_values[i] = r4_r8(&temp.r4);
- if(bin_values[i] < -1.e12 ||
- bin_values[i] > 1.e12)
- sprintf(temp_val,"%e",bin_values[i]);
- else
- sprintf(temp_val,"%f",bin_values[i]);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.r8);
- sprintf(temp_val,"%f",temp.r8);
- bin_values[i] = temp.r8;
- if(bin_values[i] < -1.e12 ||
- bin_values[i] > 1.e12)
- sprintf(temp_val,"%e",bin_values[i]);
- else
- sprintf(temp_val,"%f",bin_values[i]);
- break;
- case CDF_INT4:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.i4);
- sprintf(temp_val,"%ld",temp.i4);
- bin_values[i] = (double) temp.i4;
- break;
- case CDF_UINT4:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.ui4);
- sprintf(temp_val,"%lu",temp.ui4);
- bin_values[i] = (double) temp.ui4;
- break;
- case CDF_INT2:
- CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.i2);
- sprintf(temp_val,"%d",temp.i2);
- bin_values[i] = (double) temp.i2;
- break;
- case CDF_UINT2:
- CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.ui2);
- sprintf(temp_val,"%u",temp.ui2);
- bin_values[i] = (double) temp.ui2;
- break;
- case CDF_BYTE:
- case CDF_INT1:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.byte);
- sprintf(temp_val,"%d",temp.byte);
- bin_values[i] = (double) temp.byte;
- break;
- case CDF_UCHAR:
- case CDF_UINT1:
- rcode = CDFvarGet(CDF_id, var_id, record_num,
- indices, &temp.ubyte);
- sprintf(temp_val,"%u",temp.ubyte);
- bin_values[i] = (double) temp.ubyte;
- }
- temp_val[MINMAX_SIZE-1] = '\0';
- zero_replace(temp_val);
- strcpy(&char_values[i*MINMAX_SIZE], temp_val);
- }
- return(rcode);
- }
- void CDFLIST_output(screen, CDF, out_file, field_num)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- FILE **out_file;
- long int *field_num;
- {
- long int i, len;
- int ok;
- int termcode;
- char default_name[15],display_name[15];
- char mes[MES_COLUMNS-COL_OFFSET];
- static char file_mes[] =
- "Enter File Name w/ NO EXTENSION or hit <CR> for default ";
- static char CDF_mes[] =
- "Enter CDF Name w/ NO EXTENSION ";
- static char dot_lis[] = ".lis";
- static char file_error[] =
- "Error opening output file, using output to TERMINAL";
-
- CDFLIST_menu_keydef(screen);
- CDFLIST_select_menu_item(S.OUT_vid, S.MES_vid, &C.output,
- OUT_display, OUT_NUM_ELEMENTS, OUT_ROWS, OUT_COLUMNS, OUT_ROW_PASTE,
- OUT_COL_PASTE, MENU, &termcode);
- if(termcode != KB_CTRL_F && termcode != QUIT)
- {
- CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM-1,
- OUT_display[C.output-1].label, OUT_COLUMNS-COL_OFFSET, REVERSE);
- if(C.output != TERMIN)
- {
- if(C.output != CDFOUT)
- strcpy(CDF_display[CDF_NUM_ELEMENTS-1].label, "File Name ");
- else
- strcpy(CDF_display[CDF_NUM_ELEMENTS-1].label, "CDF Name ");
- load_vid_element(S.CDF_vid, CDF_display, CDF_NUM_ELEMENTS);
- for(i=0; i < 14; i++)
- display_name[i] = 32;
- if(C.output != CDFOUT)
- {
- CDFLIST_default_name(C.CDF_name, default_name);
- strcpy(display_name, default_name);
- }
- else
- default_name[0] = '\0';
- display_name[14] = '\0';
- CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM+1-1,
- display_name, 8, REVERSE);
- mes[0] = '\0';
- if(C.output == CDFOUT)
- strcpy(mes, CDF_mes);
- else
- {
- strcpy(mes, file_mes);
- strcat(mes, default_name);
- strcat(mes, dot_lis);
- }
- CDFLIST_put_message(S.MES_vid, mes, NOBELL, NORMAL, NOPAUSE);
- strcpy(C.file_name, default_name);
- len = strlen(C.file_name);
- for (i=len; i < 20; i++)
- C.file_name[i] = '\0';
- ok = FALSE;
- while(!ok)
- {
- input_field(S.CDF_vid, C.file_name, OUT_NAME_ROW, OUT_NAME_COL,
- OUT_NAME_LEN, &termcode);
- if(C.file_name[0] != '\0')ok = TRUE;
- }
- CDFLIST_check_name(C.file_name);
- if(C.output != CDFOUT)
- {
- strcat(C.file_name, dot_lis);
- /*
- OPEN THE FILE
- */
- *out_file = fopen(C.file_name, "w");
- if(*out_file == NULL)
- {
- CDFLIST_put_message(S.MES_vid, file_error, RINGBELL, NORMAL,
- NOPAUSE);
- C.output = TERMIN;
- CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM-1,
- OUT_display[C.output-1].label, 14, REVERSE);
- }
- }
- }
- else
- {
- begin_display_update(S.CDF_vid);
- erase_display(S.CDF_vid,
- CDF_display[CDF_NUM_ELEMENTS-1].row,
- CDF_display[CDF_NUM_ELEMENTS-1].col,
- CDF_display[CDF_NUM_ELEMENTS-1].row, CDF_COLUMNS-COL_OFFSET);
- #if defined(vms)
- end_display_update(S.CDF_vid);
- #else
- end_display_update_nobox(S.CDF_vid);
- #endif
- }
- (*field_num)++;
- }
- else
- CDFLIST_field_menu(screen, field_num);
- }
-
- void CDFLIST_default_name(string, default_name)
- char string[];
- char default_name[];
- {
-
- #if defined(unix)
- /*
- UNIX check for slash to see if a directory name is part of the CDF name
- */
- if(strchr(string, '/') != NULL)
- /*
- Copy from last occurence of the slash to end of string to pick out just CDF name
- */
- strcpy(default_name, strrchr(string, '/')+1);
- else
- /*
- No directory found in string
- */
- strcpy(default_name, string);
- #endif
-
- #ifdef vms
- /*
- VMS first check for Right Bracket to see if a directory name
- is part of the CDF name
- */
- if(strchr(string, ']') != NULL)
- strcpy(default_name, strrchr(string, ']')+1);
- /*
- VMS No right bracket check for a logical name with a colen to see if a
- directory name is part of the CDF name
- */
- else if(strchr(string, ':') != NULL)
- strcpy(default_name, strrchr(string, ':')+1);
- else
- /*
- No directory found in string
- */
- strcpy(default_name, string);
- #endif
-
- /* Patch for CD-ROMs */
- #ifdef __MSDOS__
- strcpy(default_name, "C:\\");
- if(strchr(string, '\\') != NULL)
- strcat(default_name, strrchr(string, '\\')+1);
- else if(strchr(string, ':') != NULL)
- strcat(default_name, strrchr(string, ':')+1);
- else
- strcat(default_name, string);
- #endif
-
- /* Comment out the old
- #ifdef __MSDOS__
- if(strchr(string, '\\') != NULL)
- strcpy(default_name, strrchr(string, '\\')+1);
- else if(strchr(string, ':') != NULL)
- strcpy(default_name, strrchr(string, ':')+1);
- else
- strcpy(default_name, string);
- #endif
- */
-
- /*
- Default name will be 14 characters or less to allow for output device specific
- extension
- */
- if(strlen(default_name) > 14)default_name[14] = '\0';
- }
-
- void CDFLIST_clear_row(vid, display, start_elem, end_elem, end_col)
- WINDOWid vid;
- struct vid_struct display[];
- int start_elem;
- int end_elem;
- int end_col;
- {
- long int i;
-
- int row, col;
- for (i=start_elem; i<=end_elem; i++)
- {
- row = display[i-1].row;
- col = display[i-1].field_col;
- erase_display(vid, row, col, row, end_col);
- }
- }
- void CDFLIST_file_header(CDF, select, num_select, fptr)
- struct CDF_struct *CDF;
- struct variable_struct select[];
- long int num_select;
- FILE *fptr;
- {
- long int i;
- fprintf(fptr," CDF NAME = %s\n\n",C.CDF_name);
- fprintf(fptr," VARIABLES AND SPECIFIED RANGES \n");
- fprintf(fptr,
- " ----------------------------------------------------------------------");
- fprintf(fptr,"------\n");
- for (i = 0; i < num_select; i++)
- {
- fprintf(fptr," %-19s ",select[i].var_mnemonic);
- if(select[i].filter)
- {
- if(select[i].data_type == CDF_EPOCH)
- {
- ep.tSince0 = select[i].min;
- if(SO.EPOCH_format == EPOCHFORM_DEF)
- fprintf(fptr, " %s",epochString(&ep));
- else
- fprintf(fptr, " %s",epochString1(&ep));
-
- ep.tSince0 = select[i].max;
- if(SO.EPOCH_format == EPOCHFORM_DEF)
- fprintf(fptr, " %s",epochString(&ep));
- else
- fprintf(fptr, " %s",epochString1(&ep));
-
- }
- else
- {
- if(select[i].min < -1.e12 ||
- select[i].min > 1.e12)
- fprintf(fptr, " %13.6e",select[i].min);
- else
- fprintf(fptr," %13.*f",precision(select[i].min),select[i].min);
- if(select[i].max < -1.e12 ||
- select[i].max > 1.e12)
- fprintf(fptr, " %13.6e",select[i].max);
- else
- fprintf(fptr, " %13.*f",precision(select[i].max),select[i].max);
- }
- }
- fprintf(fptr, "\n");
- }
- }
- void CDFLIST_help(screen)
- struct GLOBAL_struct *screen;
- {
- long int dummy;
- struct vid_struct *HELP_display;
- long int help_num_elements = 0;
- long int i, len;
- int tcode;
- static char help_mes[] = "Press Return key when done";
- static char help_error_mes[] = "Help not available ";
- static char help_error_mal[] = "Help not available, malloc error ";
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char temp[80];
- int help_rows, help_columns, paste_col;
- int max_len;
- static int first = TRUE;
- if(HELP_ptr != NULL)
- {
- /*
- READ text until complete and load into a vid structure
- */
- max_len = 0;
- fseek(HELP_ptr, 0l, SEEK_SET);
- while (fgets(temp,80,HELP_ptr) != NULL)
- {
- help_num_elements++;
- len = lastc(temp);
- if(len > max_len)max_len = len;
- }
- if(help_num_elements > HELP_ROWS)
- help_rows = HELP_ROWS;
- else
- help_rows = help_num_elements+ROW_OFFSET;
-
- if(max_len > HELP_COLUMNS)
- help_columns = HELP_COLUMNS;
- else
- help_columns = max_len+COL_OFFSET;
-
- paste_col = (80-help_columns)/2+1;
-
- if(first)
- create_virtual_display(help_rows, help_columns, &S.HELP_vid, BORDER, BOLD);
- first = FALSE;
- HELP_display = (struct vid_struct *)
- malloc(help_num_elements * sizeof(struct vid_struct));
- if(HELP_display == NULL)
- {
- CDFLIST_put_message(S.MES_vid, help_error_mal, RINGBELL, NORMAL,
- NOPAUSE);
- return;
- }
- fseek(HELP_ptr, 0l, SEEK_SET);
- i=0;
- for(i=0; i <help_num_elements; i++)
- {
- fgets(temp,80,HELP_ptr);
- HELP_display[i].row = 1;
- HELP_display[i].col = 1;
- len = lastc(temp) - 1;
- strncpy(HELP_display[i].label,temp,len);
- HELP_display[i].label[len] = '\0';
- }
- /*
- LOAD in the keypad definitions for this option
- */
- key_line1[0] = '\0'; key_line2[0] = '\0';
- strcat(key_line1, UP); strcat(key_line1,PUP);
- strcat(key_line2, DOWN);strcat(key_line2,PDOWN);
- strcat(key_line2,CNTRLW);
- CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
- CDFLIST_put_message(S.MES_vid, help_mes, NOBELL, NORMAL, NOPAUSE);
- /*
- Display the HELP screen
- */
- CDFLIST_select_menu_item(S.HELP_vid, S.MES_vid,
- &dummy, HELP_display, help_num_elements, help_rows, help_columns,
- HELP_ROW_PASTE, paste_col, HELP_MENU, &tcode);
- free(HELP_display);
- }
- else
- CDFLIST_put_message(S.MES_vid, help_error_mes, RINGBELL, NORMAL, NOPAUSE);
- }
- int lastc(buf)
- char *buf;
- {
- int done = FALSE;
- int i,j;
- int end;
- i = strlen(buf) + 1;
- end = i;
- j = 0;
- while(j < end && !done)
- {
- if(!isgraph(buf[i-1]))
- done = TRUE;
- else
- j++; i--;
- }
- return(i);
- }
- void CDFLIST_field_menu(screen, option)
- struct GLOBAL_struct *screen;
- long int *option;
- {
- long int cont;
- int tcode;
- long int temp;
- temp = *option+1;
- cont = CONTINUE;
- while(cont != DONE)
- {
- /*
- Choose the particular field you wish to be in
- */
- CDFLIST_menu_keydef(screen);
- CDFLIST_select_menu_item(S.FIELD_vid, S.MES_vid, &temp,
- FIELD_display, FIELD_NUM_ELEMENTS, FIELD_ROWS, FIELD_COLUMNS,
- FIELD_ROW_PASTE, FIELD_COL_PASTE, MENU, &tcode);
- *option = temp-1;
- if(*option == HELP_FIELD)
- CDFLIST_help(screen);
- else if(*option == SPECIAL_OPT_FIELD)
- CDFLIST_special_options(screen);
- else
- cont = DONE;
- }
- }
- void CDFLIST_open_screen(screen)
- struct GLOBAL_struct *screen;
- {
- create_pasteboard();
- #if defined(vms)
- begin_pasteboard_update();
- #endif
- create_virtual_display(CDF_ROWS, CDF_COLUMNS, &S.CDF_vid, BORDER, BOLD);
- paste_virtual_display(S.CDF_vid, CDF_ROW_PASTE, CDF_COL_PASTE);
- #if defined(unix)
- begin_display_update(S.CDF_vid);
- #endif
- load_vid(S.CDF_vid, CDF_display, 0, CDF_NUM_ELEMENTS-1, NO_label);
- #if defined(unix)
- end_display_update(S.CDF_vid);
- #endif
- create_virtual_display(VAR_ROWS, VAR_COLUMNS, &S.VAR_vid, BORDER, BOLD);
- paste_virtual_display(S.VAR_vid, VAR_ROW_PASTE, VAR_COL_PASTE);
- create_virtual_display(KEY_ROWS, KEY_COLUMNS, &S.KEY_vid, BORDER, BOLD);
- paste_virtual_display(S.KEY_vid, KEY_ROW_PASTE, KEY_COL_PASTE);
- create_virtual_display(MES_ROWS, MES_COLUMNS, &S.MES_vid, BORDER, BOLD);
- paste_virtual_display(S.MES_vid, MES_ROW_PASTE, MES_COL_PASTE);
- create_virtual_display(OUT_ROWS, OUT_COLUMNS, &S.OUT_vid, BORDER, BOLD);
- create_virtual_display(FIELD_ROWS, FIELD_COLUMNS, &S.FIELD_vid,
- BORDER, BOLD);
- create_virtual_display(DIS_ROWS, DIS_COLUMNS, &S.DIS_vid, BORDER, BOLD);
- create_virtual_display(DIR_ROWS, DIR_COLUMNS, &S.DIR_vid, BORDER, BOLD);
- create_virtual_display(HELP_ROWS, HELP_COLUMNS, &S.HELP_vid, BORDER, BOLD);
- create_virtual_display(SPECIAL_ROWS, SPECIAL_COLUMNS, &S.SPECIAL_vid,
- BORDER, BOLD);
- create_virtual_display(EPOCHFORMAT_ROWS, EPOCHFORMAT_COLUMNS,
- &S.EPOCHFORMAT_vid, BORDER, BOLD);
- /*
- create_virtual_display(VARFORMAT_ROWS, VARFORMAT_COLUMNS,
- &S.VARFORMAT_vid, BORDER, BOLD);
- create_virtual_display(MINMAX_ROWS, MINMAX_COLUMNS, &S.MINMAX_vid,
- BORDER, BOLD);
- create_virtual_display(FILTER_ROWS, FILTER_COLUMNS, &S.FILTER_vid,
- BORDER, BOLD);
- create_virtual_display(FILLVALUE_ROWS, FILLVALUE_COLUMNS, &S.FILLVALUE_vid,
- BORDER, BOLD);
- */
- create_virtual_display(VARSELECT_ROWS, VARSELECT_COLUMNS, &S.VARSELECT_vid,
- BORDER, BOLD);
- load_vid(S.VAR_vid, init_display, 0, VAR_NUM_ELEMENTS, VAR_label);
- load_vid(S.KEY_vid, KEY_display, 0, KEY_NUM_ELEMENTS, KEY_label);
- load_vid(S.MES_vid, MES_display, 0, MES_NUM_ELEMENTS, MES_label);
- #if defined(vms)
- end_pasteboard_update();
- enable_trap(S.MES_vid);
- #endif
-
- }
- void CDFLIST_special_options(screen)
- struct GLOBAL_struct *screen;
- {
- int tcode;
- int field_num;
- static char star[] = "*";
- static char EPFIELD_mes[] =
- "Select desired EPOCH display format, Q to leave Special Option Window";
- /*
- static char noformat_mes[] =
- "This CDF does not a contain the attribute FORMAT, switching back to default";
- static char nofillval_mes[] =
- "This CDF does not a contain the attribute FILLVAL, switching back to default";
- */
- #if defined(vms)
- begin_pasteboard_update();
- #endif
-
- paste_virtual_display(S.SPECIAL_vid, SPECIAL_ROW_PASTE, SPECIAL_COL_PASTE);
- label_border(S.SPECIAL_vid, SPECIAL_label, strlen(SPECIAL_label));
- paste_virtual_display(S.EPOCHFORMAT_vid, EPOCHFORMAT_ROW_PASTE,
- EPOCHFORMAT_COL_PASTE);
- load_vid(S.EPOCHFORMAT_vid, EPOCHFORMAT_display, 0,
- EPOCHFORMAT_NUM_ELEMENTS, EPOCHFORMAT_label);
- /*
- paste_virtual_display(S.VARFORMAT_vid, VARFORMAT_ROW_PASTE,
- VARFORMAT_COL_PASTE);
- load_vid(S.VARFORMAT_vid, VARFORMAT_display, 0,
- VARFORMAT_NUM_ELEMENTS, VARFORMAT_label);
-
- paste_virtual_display(S.FILTER_vid, FILTER_ROW_PASTE, FILTER_COL_PASTE);
- load_vid(S.FILTER_vid, FILTER_display, 0, FILTER_NUM_ELEMENTS, FILTER_label);
- paste_virtual_display(S.FILLVALUE_vid, FILLVALUE_ROW_PASTE,
- FILLVALUE_COL_PASTE);
- load_vid(S.FILLVALUE_vid, FILLVALUE_display, 0, FILLVALUE_NUM_ELEMENTS,
- FILLVALUE_label);
- paste_virtual_display(S.MINMAX_vid, MINMAX_ROW_PASTE, MINMAX_COL_PASTE);
- load_vid(S.MINMAX_vid, MINMAX_display, 0, MINMAX_NUM_ELEMENTS, MINMAX_label);
- */
- #if defined(vms)
- end_pasteboard_update();
- #endif
-
- put_chars(S.EPOCHFORMAT_vid, star, 1, SO.EPOCH_format, 2, NOERASE, NORMAL);
- /*
- put_chars(S.VARFORMAT_vid, star, 1, SO.variable_format, 2, NOERASE, NORMAL);
- put_chars(S.FILTER_vid, star, 1, SO.filters, 2, NOERASE, NORMAL);
- put_chars(S.FILLVALUE_vid, star, 1, SO.fill_values, 2, NOERASE, NORMAL);
- put_chars(S.MINMAX_vid, star, 1, SO.minmax, 2, NOERASE, NORMAL);
- */
- CDFLIST_special_keydef(screen);
- tcode = CONTINUE;
- field_num = EPOCHFORMAT_FIELD;
- while(tcode != QUIT)
- {
- switch(field_num)
- {
- case EPOCHFORMAT_FIELD:
- CDFLIST_put_message(S.MES_vid, EPFIELD_mes, NOBELL, NORMAL,
- NOPAUSE);
- tcode = CDFLIST_special_option_menu(S.EPOCHFORMAT_vid,
- &SO.EPOCH_format, EPOCHFORMAT_NUM_ELEMENTS);
- tcode = QUIT;
- break;
- }
- }
- /*
- case VARFORMAT_FIELD:
- tcode = CDFLIST_special_option_menu(S.VARFORMAT_vid,
- &SO.variable_format, VARFORMAT_NUM_ELEMENTS);
- if(!SO.format_attr && SO.variable_format == FORMAT)
- {
- SO.variable_format = NOFORMAT;
- CDFLIST_put_message(S.MES_vid, noformat_mes, RINGBELL, NORMAL,
- PAUSE);
- CDFLIST_disp_opt(S.VARFORMAT_vid, SO.variable_format,
- VARFORMAT_NUM_ELEMENTS);
- }
- break;
- case FILTER_FIELD:
- tcode = CDFLIST_special_option_menu(S.FILTER_vid,
- &SO.filters, FILTER_NUM_ELEMENTS);
- break;
- case FILLVALUE_FIELD:
- tcode = CDFLIST_special_option_menu(S.FILLVALUE_vid,
- &SO.fill_values, FILLVALUE_NUM_ELEMENTS);
- if(!SO.fillval_attr && SO.fill_values == FILLVAL)
- {
- SO.fill_values = NOFILLVAL;
- CDFLIST_put_message(S.MES_vid, nofillval_mes, RINGBELL,
- NORMAL, PAUSE);
- CDFLIST_disp_opt(S.FILLVALUE_vid, SO.fill_values,
- FILLVALUE_NUM_ELEMENTS);
- }
- break;
- case MINMAX_FIELD:
- tcode = CDFLIST_special_option_menu(S.MINMAX_vid,
- &SO.minmax, MINMAX_NUM_ELEMENTS);
- break;
- }
-
- field_num++;
- }
- */
- #if defined(vms)
- begin_pasteboard_update();
- #endif
- /*
- unpaste_virtual_display(S.MINMAX_vid);
- unpaste_virtual_display(S.FILLVALUE_vid);
- unpaste_virtual_display(S.FILTER_vid);
- unpaste_virtual_display(S.VARFORMAT_vid);
- */
- unpaste_virtual_display(S.EPOCHFORMAT_vid);
- unpaste_virtual_display(S.SPECIAL_vid);
- CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
- #if defined(vms)
- end_pasteboard_update();
- #endif
-
-
- }
- int CDFLIST_special_option_menu(vid, value, num_rows)
- WINDOWid vid;
- int *value;
- int num_rows;
- {
- int done;
- int row,col;
- int tcode;
-
- done = FALSE;
- row = *value;
- col = 2;
- while(!done)
- {
- set_cursor_abs(vid, row, col);
- #ifdef vms
- read_input(&tcode);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- read_input(vid, &tcode);
- #endif
- switch(tcode)
- {
- case QUIT:
- case quit:
- case KB_CTRL_F:
- tcode = QUIT;
- done = TRUE;
- break;
- case KB_RETURN:
- case KB_PAD_ENTER:
- tcode = KB_RETURN;
- done = TRUE;
- break;
- case KB_UPARROW:
- row--;
- if(row < 1)row = num_rows;
- break;
- case KB_DOWNARROW:
- row++;
- if(row > num_rows)row = 1;
- break;
- case KB_REDRAW:
- redraw_screen();
- break;
- }
- CDFLIST_disp_opt(vid, row, num_rows);
- }
-
- *value = row;
- return(tcode);
- }
- void CDFLIST_disp_opt(vid, row, num_rows)
- WINDOWid vid;
- int row;
- int num_rows;
- {
- int i;
- static char star[] = "*";
- static char blank[] = " ";
-
- for(i=1; i<=num_rows;i++)
- {
- if(i == row)
- put_chars(vid, star, 1, i, 2, NOERASE, NORMAL);
- else
- put_chars(vid, blank, 1, i, 2, NOERASE, NORMAL);
- }
- }
-
- #if defined(unix) | defined(__MSDOS__)
- void CDFLIST_draw_main_screen(screen)
- struct GLOBAL_struct *screen;
- {
- repaste_virtual_display(S.CDF_vid, CDF_ROW_PASTE, CDF_COL_PASTE);
- repaste_virtual_display(S.VAR_vid, VAR_ROW_PASTE, VAR_COL_PASTE);
- label_border(S.VAR_vid, VAR_label, strlen(VAR_label));
- repaste_virtual_display(S.KEY_vid, KEY_ROW_PASTE, KEY_COL_PASTE);
- label_border(S.KEY_vid, KEY_label, strlen(KEY_label));
- repaste_virtual_display(S.MES_vid, MES_ROW_PASTE, MES_COL_PASTE);
- label_border(S.MES_vid, MES_label, strlen(MES_label));
- }
- #endif
-
- void CDFLIST_select_menu_item(vid, MES_vid, rvalue, display,
- num_elements, num_rows, num_columns, row_start, col_start, mode, termcode)
- WINDOWid vid;
- WINDOWid MES_vid;
- long int *rvalue;
- struct vid_struct display[];
- long int num_elements;
- int num_rows;
- int num_columns;
- int row_start;
- int col_start;
- int mode;
- int *termcode;
- {
- long int in_value;
- int row, col;
- int tcode;
- long int done;
- long int num_screen;
- long int start_page;
- long int end;
- long int value;
- int row1 = 1;
- int col1 = 1;
- static char top[] = "Top of menu";
- static char bottom[] = "Bottom of menu";
-
- in_value = *rvalue;
- /*
- Find out the number of rows to be on the screen at one time
- */
- num_rows = num_rows - ROW_OFFSET;
- num_columns = num_columns - COL_OFFSET;
- if(num_elements > num_rows)
- num_screen = num_rows;
- else
- num_screen = num_elements;
- /*
- Erase and load data into the menu for selection
- */
- value = 1;
- row = 1;
- col = 1;
- #if !defined(vms)
- begin_display_update(vid);
- #endif
- erase_display(vid, 1, 1, num_rows, num_columns);
- load_menu(vid, display, num_screen, NO_label);
- change_rendition(vid,1,1,num_rows,num_columns,NORMAL);
- paste_virtual_display(vid, row_start, col_start);
- #if !defined(vms)
- end_display_update(vid);
- #endif
- start_page = 1;
- if(mode == MENU)change_rendition(vid, row, col, 1, num_columns, REVERSE);
- done = FALSE;
- while(!done)
- {
- set_cursor_abs(vid, row, col);
- #ifdef vms
- read_input(&tcode);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- read_input(vid, &tcode);
- #endif
- switch (tcode)
- {
- case KB_DOWNARROW:
- if(row == num_rows || value == num_elements)
- if(value < num_elements)
- {
- /*
- SCROLL UP
- */
- value++; start_page++;
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1),
- num_screen, NO_label);
- end_display_update(vid);
- }
- else
- {
- value = 1;
- row = 1;
- start_page = 1;
- begin_display_update(vid);
- erase_display(vid, 1, 1, num_rows, num_columns);
- load_menu(vid, display, num_screen, NO_label);
- end_display_update(vid);
- }
- else
- {
- row++; value++;
- }
- break;
- case KB_UPARROW:
- if(row > 1)
- {
- row--;
- value--;
- }
- else if(value > 1)
- {
- /*
- SCROLL DOWN
- */
- value--; start_page--;
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1),
- num_screen, NO_label);
- end_display_update(vid);
- }
- else
- {
- start_page = num_elements - num_screen + 1;
- value = num_elements;
- row = num_screen;
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1),
- num_screen, NO_label);
- end_display_update(vid);
- }
- break;
- /*
- PAGE DOWN
- */
- case PAGEdown:
- case PAGEDOWN:
- start_page = start_page + num_screen;
- end = start_page + num_screen - 1;
- value = value + num_screen;
- if(end > num_elements)
- {
- /*
- Display the next page down
- */
- end = num_elements;
- start_page = end - num_screen + 1;
- value = num_elements;
- row = num_rows;
- CDFLIST_put_message(MES_vid, bottom, NOBELL, NORMAL, NOPAUSE);
- }
- begin_display_update(vid);
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1), num_screen, NO_label);
- end_display_update(vid);
- break;
- /*
- PAGE UP
- */
- case PAGEUP:
- case PAGEup:
- start_page = start_page - num_screen;
- value = value - num_screen;
- if(start_page < 1)
- {
- start_page = 1;
- value = 1;
- row = 1;
- CDFLIST_put_message(MES_vid, top, NOBELL, NORMAL, NOPAUSE);
- }
- begin_display_update(vid);
- /*
- Display the next page up
- */
- erase_display(vid, row1, col1, num_rows, num_columns);
- load_menu(vid, display+(start_page-1), num_screen, NO_label);
- end_display_update(vid);
- break;
- case KB_RETURN:
- case KB_PAD_ENTER:
- done = TRUE;
- *rvalue = value;
- *termcode = KB_RETURN;
- break;
- case QUIT:
- case quit:
- done = TRUE;
- *rvalue = in_value;
- *termcode = QUIT;
- break;
- case KB_CTRL_F:
- done = TRUE;
- *rvalue = value;
- *termcode = KB_CTRL_F;
- break;
- case KB_REDRAW:
- repaint_screen();
- break;
- default:
- break;
- }
- if(mode == MENU)
- {
- change_rendition(vid, 1, 1, num_rows, num_columns, NORMAL);
- change_rendition(vid, row, 1, 1, num_columns, REVERSE);
- }
- }
- unpaste_virtual_display(vid);
- }
- void CDFLIST_CDF_info(screen, CDF, CDF_display, OUT_display)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct vid_struct CDF_display[];
- struct vid_struct OUT_display[];
- {
- char string[21]; /* V1.4 */
- char temp[7]; /* V1.4 */
- long int i;
- sprintf(string, "%ld ", C.num_dims);
- CDFLIST_clear_row(S.CDF_vid, CDF_display, 2, 2, 28);
- CDFLIST_put_selection(S.CDF_vid, CDF_display, NUMDIM_ELEMENT_NUM-1, string,
- 2, REVERSE);
- string[0] = '\0';
- CDFLIST_clear_row(S.CDF_vid, CDF_display, 3, 3, 28);
- if(C.num_dims > 0)
- {
- for (i=0; i < C.num_dims; i++)
- {
- sprintf(temp, "%ld ", C.dim_sizes[i]);
- strcat(string, temp);
- }
- }
- else
- string[0] = '\0';
- CDFLIST_put_selection(S.CDF_vid, CDF_display, DIMSIZ_ELEMENT_NUM-1, string,
- 10, REVERSE);
- sprintf(string, "%ld ", C.num_vars);
- CDFLIST_clear_row(S.CDF_vid, CDF_display, 4, 4, 56);
- CDFLIST_put_selection(S.CDF_vid, CDF_display, NUMVAR_ELEMENT_NUM-1, string,
- 6, REVERSE);
- sprintf(string, "%ld ", C.max_record_num+1);
- CDFLIST_clear_row(S.CDF_vid, CDF_display, 5, 5, 53);
- CDFLIST_put_selection(S.CDF_vid, CDF_display, NUMREC_ELEMENT_NUM-1, string,
- 6, REVERSE);
- CDFLIST_put_selection(S.CDF_vid, CDF_display, OUT_ELEMENT_NUM-1,
- OUT_display[C.output-1].label, 8, REVERSE);
- }
- void load_vid(vid, display, start_elem, num_elements, label)
- WINDOWid vid;
- struct vid_struct display[];
- int start_elem;
- int num_elements;
- char label[];
- {
- long int i;
- int len;
- long int end_elem;
- int erase_mode = NOERASE;
- int video_type = NORMAL;
-
- len = strlen(label);
- if(len > 0)label_border(vid, label, len);
- end_elem = start_elem + num_elements;
- for(i=start_elem; i< end_elem; i++)
- {
- len = strlen(display[i].label);
- put_chars(vid, display[i].label, len,
- display[i].row, display[i].col, erase_mode, video_type);
- }
- }
- void load_vars(vid, display, start_num, max_vars)
- WINDOWid vid;
- struct vid_struct display[];
- long int start_num;
- long int max_vars;
- {
- long int i;
- int len;
- long int erase_mode = NOERASE;
- long int video_type = NORMAL;
- long int elem;
- int row;
- long int bump;
- long int end_num;
- end_num = start_num + 8;
- begin_display_update(vid);
- erase_display(vid, 2, 6, 9, VAR_COLUMNS-COL_OFFSET);
- bump = 0;
- row = 1;
- for(i=start_num; i< end_num; i++)
- {
- elem = i<=max_vars ? i*3 : (i-max_vars)*3;
- if(elem >= 0 && elem <= 2)bump = 3;
- row++;
- len = strlen(display[elem+bump].label);
- if(len > 0)
- {
- put_chars(vid, display[elem+bump].label, len,
- row, display[elem+bump].col, erase_mode, video_type);
- change_rendition ( vid, row, 6, 1, len-6+1, REVERSE);
- len = strlen(display[elem+bump+1].label);
- put_chars(vid, display[elem+bump+1].label, len,
- row, display[elem+bump+1].col, erase_mode, video_type);
- len = strlen(display[elem+bump+2].label);
- put_chars(vid, display[elem+bump+2].label, len,
- row, display[elem+bump+2].col, erase_mode, video_type);
- }
- }
- #if defined(vms)
- end_display_update(vid);
- #else
- end_display_update_nobox(vid);
- #endif
- }
- void load_vid_element(vid, display, element_num)
- WINDOWid vid;
- struct vid_struct display[];
- int element_num;
- {
-
- int len;
-
- int erase_mode = NOERASE;
- int video_type = NORMAL;
-
- len = strlen(display[element_num-1].label);
- put_chars(vid, display[element_num-1].label, len,
- display[element_num-1].row, display[element_num-1].col, erase_mode, video_type);
- }
- void CDFLIST_load_keydef(vid, line1, line2)
- WINDOWid vid;
- char line1[];
- char line2[];
- {
- int row, col;
- int erase_mode;
- int video_type;
- int len;
- begin_display_update(vid);
- erase_display(vid, 1, 1, KEY_ROWS-ROW_OFFSET, KEY_COLUMNS-COL_OFFSET);
- row = 1; col = 1; erase_mode = ERASE; video_type = NORMAL;
- len = strlen(line1);
- if(len > (KEY_COLUMNS-COL_OFFSET))len = KEY_COLUMNS - COL_OFFSET;
- put_chars(vid, line1, len, row, col, erase_mode, video_type);
- len = strlen(line2);
- row = 2; col = 1; erase_mode = ERASE; video_type = NORMAL;
- if(len > (KEY_COLUMNS-COL_OFFSET))len = KEY_COLUMNS - COL_OFFSET;
- put_chars(vid, line2, len, row, col, erase_mode, video_type);
- #if defined(vms)
- end_display_update(vid);
- #else
- end_display_update_nobox(vid);
- #endif
- }
- void CDFLIST_put_selection(vid, display, element_num, selection,
- field_len, video_type)
- WINDOWid vid;
- struct vid_struct display[];
- int element_num;
- char selection[];
- int field_len;
- int video_type;
- {
- int len;
-
- int erase_mode = NOERASE;
- int row, col, end_col;
-
- len = strlen(display[element_num].label);
- row = display[element_num].row;
- col = display[element_num].field_col;
- len = strlen(selection);
- end_col = col + field_len - 1;
- erase_display(vid, row, col, row, end_col);
- put_chars(vid, selection, len, row, col, erase_mode, video_type);
- }
- void CDFLIST_put_select_row(vid, display, row, element_num, selection,
- field_len, video_type)
- WINDOWid vid;
- struct vid_struct display[];
- int row;
- int element_num;
- char selection[];
- int field_len;
- int video_type;
- {
- int len;
-
- int erase_mode = NOERASE;
- int col, end_col;
-
- len = strlen(display[element_num].label);
- col = display[element_num].field_col;
- len = strlen(selection);
- end_col = col + field_len - 1;
- erase_display(vid, row, col, row, end_col);
- put_chars(vid, selection, len, row, col, erase_mode, video_type);
- }
- void CDFLIST_put_value(vid, display, row, element_num, bin_value)
- WINDOWid vid;
- struct vid_struct display[];
- int row;
- int element_num;
- double bin_value;
- {
- char value[20];
- int i;
- int len;
-
- long int erase_mode = NOERASE;
- int video_type = NORMAL;
- int col, end_col;
-
- len = strlen(display[element_num].label);
- col = display[element_num].col;
- end_col = col + 20;
- erase_display(vid, row, col, row, end_col);
- if(bin_value < -1.e12 || bin_value > 1.e12)
- {
- sprintf(value,"%14.6e",bin_value);
- CDFLIST_left_justify(value);
- }
- else
- {
- sprintf(value,"%f",bin_value);
- zero_replace(value);
- }
- len = strlen(value);
- for(i = len; i<14; i++)
- value[i] = ' ';
- value[14] = '\0';
- len = 14;
- put_chars(vid, value, len, row, col, erase_mode, video_type);
- strcpy(display[element_num].label, value);
- }
- void CDFLIST_put_TIME(vid, display, row, element_num, time)
- WINDOWid vid;
- struct vid_struct display[];
- int row;
- int element_num;
- double time;
- {
- char value[80];
- int len;
-
- int erase_mode = NOERASE;
- int video_type = NORMAL;
- int col, end_col;
-
- len = EPOCH_WIDTH;
- col = display[element_num].col;
- end_col = col + EPOCH_WIDTH;
- erase_display(vid, row, col, row, end_col);
- ep.tSince0 = time;
- strcpy(value, epochString(&ep));
- put_chars(vid, value, len, row, col, erase_mode, video_type);
- strcpy(display[element_num].label, value);
- }
- void CDFLIST_put_message(vid, message, rbell, video_type, pause)
- WINDOWid vid;
- char message[];
- int rbell;
- int video_type;
- int pause;
- {
- int len;
-
- int erase_mode = ERASE;
- int row, col;
- #if defined (vms)
- float wait = 3.; /*jtl*/
- #endif
-
- len = strlen(message);
- row = 1;
- col = 1;
- if(rbell == RINGBELL)
- #if defined(vms)
- ring_bell(vid);
- #else
- ring_bell();
- #endif
- if(len > (MES_COLUMNS-COL_OFFSET))len = MES_COLUMNS - COL_OFFSET;
- put_chars(vid, message, len, row, col, erase_mode, video_type);
- if(pause == PAUSE)
- #ifdef vms
- lib$wait(&wait);
- #endif
-
- #if defined(unix) | defined(__MSDOS__)
- sleep(3);
- #endif
-
- }
- void load_menu(vid, display, num_elements, label)
- WINDOWid vid;
- struct vid_struct display[];
- int num_elements;
- char label[];
- {
- int i;
- int len;
-
- int erase_mode = NOERASE;
- int video_type = NORMAL;
- int row;
- int col = 1;
- len = strlen(label);
- if(len > 0)label_border(vid, label, len);
- for(i=0; i< num_elements; i++)
- {
- row = i + 1;
- len = strlen(display[i].label);
- put_chars(vid, display[i].label, len, row, col,
- erase_mode, video_type);
- }
- }
- void zero_replace(string)
- char string[];
- {
- long int zero_index;
- long int byte;
- long int found = FALSE;
- long int len;
-
- CDFLIST_left_justify(string);
- byte = 0;
- len = strlen(string);
- while(byte < len && !found)
- {
- if(string[byte] == PERIOD)found = TRUE;
- byte++;
- }
- if(found)
- {
- zero_index = byte;
- while(byte < len)
- {
- if(string[byte] == '0')
- {
- if(zero_index == 0)zero_index = byte;
- }
- else
- zero_index = 0;
- byte++;
- }
- if(zero_index > 0)
- {
- for (byte=zero_index; byte<len; byte++)
- string[byte] = ' ';
- }
- }
- }
- void CDFLIST_check_name(string)
- char string[];
- {
- char temp_name[14];
- long int byte;
- long int found;
- CDFLIST_left_justify(string);
- byte = 0;
- while(string[byte] != '\0')
- {
- if(string[byte] == 32)string[byte] = '\0';
- byte++;
- }
- byte = 0;
-
- found = FALSE;
- while(string[byte] != '\0' && !found)
- {
- if(string[byte] == PERIOD)
- {
- found = TRUE;
- temp_name[byte] = '\0';
- }
- else
- temp_name[byte] = string[byte];
- byte++;
- }
-
- temp_name[byte] = '\0';
- strcpy(string, temp_name);
- }
- void CDFLIST_left_justify (field)
- char field[];
- {
- long int i;
- long int index;
- long int done;
- char *temp;
- long int len;
- len = strlen(field);
- temp = (char *) malloc(len); /* V1.5 */
- if(temp == NULL)return;
- /* Blank out temporary hold area */
-
- for (i = 0; i < len; i++)
- temp[i] = ' ';
-
-
- done = FALSE;
- for (index = 0; done != TRUE && index <= len; index++)
-
- {
- /* Look for a non-blank character */
-
- if(field[index] != ' ')
- {
- /* Left Justify by copying from the non-blank character to the end of field */
-
- strncpy(temp,field+index,len-index);
- for (i = 0; i < len; i++)
- field[i] = ' ';
-
- /* Now copy from the temporary field back to the permanent field */
-
- strncpy(field, temp, len);
- done = TRUE;
- }
- }
- free(temp);
- }
- void CDFLIST_print_header(select, num_select, max_term, output, fptr, first)
- struct variable_struct select[];
- long int num_select;
- long int max_term;
- long int output;
- FILE *fptr;
- long int first;
- {
- long int i;
- for (i = 0; i < num_select; i++)
- {
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #if defined(vms)
- printf(" %s",select[i].header_name);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %s",select[i].header_name);
- #endif
- if((output == FILEOUT || output == TERMFILE) && (first))
- fprintf(fptr," %s",select[i].header_name);
- }
- if(output == TERMIN || output == TERMFILE)
- #ifdef vms
- printf("\n");
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr,"\n");
- #endif
- if((output == FILEOUT || output == TERMFILE) && (first))
- fprintf(fptr,"\n");
- }
- void CDFLIST_print_data(select, data_values, num_select, max_term,
- output, fptr)
- struct variable_struct select[];
- union mixed data_values[];
- long int num_select;
- long int max_term;
- long int output;
- FILE *fptr;
- {
- long int i;
- double value;
- char time[25];
-
- for (i = 0; i < num_select; i++)
- {
- if(select[i].data_type == CDF_EPOCH)
- {
- ep.tSince0 = data_values[i].r8;
- if(SO.EPOCH_format == EPOCHFORM_DEF)
- strcpy(time, epochString(&ep));
- else
- strcpy(time, epochString1(&ep));
- if((output == TERMIN || output == TERMFILE) &&
- ( i< max_term))
- #ifdef vms
- printf(" %s",time);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %s",time);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr, " %s",time);
- }
- else if(select[i].data_type == CDF_CHAR ||
- select[i].data_type == CDF_UCHAR)
- {
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %s",data_values[i].string);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %s",data_values[i].string);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr, " %s",data_values[i].string);
- }
- else
- {
- switch(select[i].data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- value = (double) data_values[i].r4;
- if((output == TERMIN || output == TERMFILE) &&
- ( i< max_term))
- {
- #if defined(vms)
- if(value < -1.e12 ||
- value > 1.e12)
- printf(" %13.6e",value);
- else
- printf(" %13.*f",precision(value),value);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- if(value < -1.e12 ||
- value > 1.e12)
- wprintw(stdscr," %13.6e",value);
- else
- wprintw(stdscr," %13.*f",precision(value),value);
- #endif
- }
- if(output == FILEOUT|| output == TERMFILE)
- {
- if(value < -1.e12 ||
- value > 1.e12)
- fprintf(fptr," %13.6e",value);
- else
- fprintf(fptr, " %13.*f",precision(value), value);
- }
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- value = data_values[i].r8;
- if((output == TERMIN || output == TERMFILE) &&
- ( i< max_term))
- {
- #ifdef vms
- if(value < -1.e12 ||
- value > 1.e12)
- printf(" %13.6e",value);
- else
- printf(" %13.*f",precision(value),value);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- if(value < -1.e12 ||
- value > 1.e12)
- wprintw(stdscr," %13.6e",value);
- else
- wprintw(stdscr," %13.*f",precision(value),value);
- #endif
- }
- if(output == FILEOUT|| output == TERMFILE)
- {
- if(value < -1.e12 ||
- value > 1.e12)
- fprintf(fptr," %13.6e",value);
- else
- fprintf(fptr, " %13.*f",precision(value), value);
- }
- break;
- case CDF_INT4:
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %11ld ",data_values[i].i4);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %11ld ",data_values[i].i4);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr, " %11ld ",data_values[i].i4);
- break;
- case CDF_UINT4:
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %10lu ",data_values[i].ui4);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %10lu ",data_values[i].ui4);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr, " %10lu ",data_values[i].ui4);
- break;
- case CDF_INT2:
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %6d ",data_values[i].i2);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %6d ",data_values[i].i2);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr," %6d ",data_values[i].i2);
- break;
- case CDF_UINT2:
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %6u ",data_values[i].ui2);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %6u ",data_values[i].ui2);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr," %6u ",data_values[i].ui2);
- break;
- case CDF_BYTE:
- case CDF_INT1:
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %4d ",data_values[i].byte);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %4d ",data_values[i].byte);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr," %4d ",data_values[i].byte);
- break;
- case CDF_UINT1:
- if((output == TERMIN || output == TERMFILE) &&
- (i< max_term))
- #ifdef vms
- printf(" %3u ",data_values[i].ubyte);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr," %3u ",data_values[i].ubyte);
- #endif
- if(output == FILEOUT|| output == TERMFILE)
- fprintf(fptr," %3u ",data_values[i].ubyte);
- }
- }
- }
- if(output == TERMIN || output == TERMFILE)
- #ifdef vms
- printf("\n");
- #endif
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr,"\n");
- #endif
- if(output == FILEOUT || output == TERMFILE)
- fprintf(fptr,"\n");
- }
- void CDFLIST_var_menus(screen, CDF, var_rows, var_columns)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- int *var_rows;
- int *var_columns;
- {
- /*
- create the virtual display for the variables in the CDF, number of rows
- depends on the the number of variables, add 1 for select_var option
- */
- if((C.num_vars+ROW_OFFSET+1) > VARSELECT_ROWS)
- *var_rows = VARSELECT_ROWS;
- else
- *var_rows = C.num_vars + ROW_OFFSET + 1;
- if((C.max_var_len+COL_OFFSET) > VARSELECT_COLUMNS)
- *var_columns = VARSELECT_COLUMNS;
- else
- *var_columns = C.max_var_len+COL_OFFSET;
- create_virtual_display(*var_rows, *var_columns,
- &S.VARSELECT_vid, BORDER, BOLD);
- }
- CDFstatus CDFLIST_close(CDF)
- struct CDF_struct *CDF;
- {
- CDFstatus rcode;
-
- rcode = CDFclose(C.CDF_id);
-
- return(rcode);
- }
- void CDFLIST_close_screen()
- {
- delete_pasteboard(ERASE);
- }
- double r4_r8(r4_ptr)
- float *r4_ptr;
- {
- float r4;
- /*
- Convert float to double
- Based on assumption that float contains 7 significant digits
- */
- double r4r8;
- double fracr8;
- float realexp,temp,rfrac,x;
- double base, power,exp;
- long int frac;
- long int evalue;
- r4 = *r4_ptr;
- /*
- If the REAL*4 value is 0 then just set the REAL*8 value to 0 and return
- */
- if(r4 == 0.) return(0.);
-
- temp = r4;
- evalue = 0;
- /*
- Calculate the exponent of the incoming REAL*4 value
- If absolute value ge 10 exponent is positive
- If absolute value lt 1 exponent is negative
- */
- if(fabs(temp) >= 10.)
- {
- while(fabs(temp) >= 10.)
- {
- evalue = evalue + 1;
- temp = temp / 10.;
- }
- }
- else if(fabs(temp) < 1.)
-
- {
- while(fabs(temp) < 1.)
- {
- evalue = evalue - 1;
- temp = temp * 10.;
- }
-
- }
- /*
- Extract out the fractional portion of the real value
- */
- /*
- exp = (long int) r4;
- realexp = (float) exp;
- rfrac = r4-realexp;
- */
- if(r4 > 0.)
- exp = floor(r4);
- else
- exp = ceil(r4);
- realexp = (float) exp;
- rfrac = r4 - realexp;
- /*
- Convert significant digits of fraction portion to integer by multiplying.
- */
- base = 10.;
- power = (double) (6-evalue);
- x = rfrac*pow(base,power);
- if(x > 0.)
- frac = (long int) (x + .5);
- else
- frac = (long int) (x - .5);
- fracr8 = (double) frac;
- r4r8 = exp;
- /*
- Convert the integer back into a fraction by diving.
- then ADD back in the integer portion.
- */
- r4r8 = r4r8 + fracr8/(pow(base, power));
- return(r4r8);
- }
- void CDFLIST_valid_minmax (CDF_id, attr_num, field_num, scale, rcode)
-
- CDFid CDF_id;
- long attr_num;
- long field_num;
- double *scale;
- CDFstatus *rcode;
- {
- float r4;
- long int i4;
- unsigned long int ui4;
- short int i2;
- unsigned short int ui2;
- Schar byte;
- Uchar ubyte;
- long data_type;
- long num_elements;
-
- *rcode = CDFattrEntryInquire(CDF_id, attr_num, field_num, &data_type,
- &num_elements);
- if(*rcode < CDF_OK) return;
- switch(data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &r4);
- *scale = r4_r8(&r4);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, scale);
- break;
- case CDF_INT4:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &i4);
- *scale = (double) i4;
- break;
- case CDF_UINT4:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &ui4);
- *scale = (double) ui4;
- break;
- case CDF_INT2:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &i2);
- *scale = (double) i2;
- break;
- case CDF_UINT2:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &ui2);
- *scale = (double) ui2;
- break;
- case CDF_BYTE:
- case CDF_INT1:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &byte);
- *scale = (double) byte;
- break;
- case CDF_UINT1:
- *rcode = CDFattrGet(CDF_id, attr_num, field_num, &ubyte);
- *scale = (double) ubyte;
- }
- }
- void init_var_display(display, num_vars)
- struct vid_struct *display;
- long int num_vars;
- {
- long int i;
- long int num;
- long int index;
- char temp[10];
- display[0].row = 1;
- display[0].col = 6;
- strcpy(display[0].label, "Variable");
- display[0].field_col = 6;
- display[1].row = 1;
- display[1].col = 26;
- strcpy(display[1].label, "Minimum");
- display[1].field_col = 26;
- display[2].row = 1;
- display[2].col = 52;
- strcpy(display[2].label, "Maximum");
- display[2].field_col = 52;
- if(num_vars < 8)
- num = 8;
- else
- num = num_vars;
-
- for(i=1; i<=num; i++)
- {
- index = (i-1)*3;
- display[index+3].row = i+1;
- display[index+3].col = 1;
- sprintf(temp, "%3ld) ",i);
- strcpy(display[index+3].label, temp);
- display[index+3].field_col = 6;
- display[index+4].row = i+1;
- display[index+4].col = 26;
- display[index+4].label[0] = '\0';
- display[index+4].field_col = 26;
- display[index+5].row = i+1;
- display[index+5].col = 52;
- display[index+5].label[0] = '\0';
- display[index+5].field_col = 52;
- }
- }
-